<?php defined('_JEXEC') or die('Restricted access'); ?>
<?php JHTML::_('behavior.formvalidation'); ?>
<script type="text/javascript">
function myValidate(form) {
	var error = '';
	var ok = true;
	for(i=0; i<form.elements.length; i++){
		if (! document.formvalidator.validate(form.elements[i])) {
			if( ok ) ok = false;

			switch(form.elements[i].name){
				case 'id':
						error += 'System user is required!\n';
					break;
				case 'tsb_role_id':
						error += 'Role is required!\n';
					break;
			}
		}
	}
	if(error != '')
		alert(error);

	if(ok)
		form.check.value='<?php echo JUtility::getToken(); ?>';//send token

	return ok;
}

//Override the base function in folder: include/js/joomla.javascript.js
function submitbutton(pressbutton) {
	if(pressbutton.toUpperCase() != 'CANCEL'){
		if(myValidate(document.adminForm))
			submitform(pressbutton);
	}else{
		submitform(pressbutton)
	}
}
</script>

<form action="index.php" method="post" name="adminForm" id="adminForm" class="form-validate" onsubmit="return false">
<input type="hidden" name="check" value="post"/>

<div class="col100">
	<fieldset class="adminform">
		<legend><?php echo JText::_( 'Details' ); ?></legend>
		<table class="admintable">
		<tr>
			<td style="width: 200px" align="right" class="key">
				<label for="name">
					<?php echo JText::_( 'SYSTEM USERS' ); ?>:
				</label>
			</td>
			<td>
				<select class="text_area required" name="id" id="id">
				<?php
				foreach ($this->system_users as $system_user) {
					echo "<option value=\"".$system_user->id."\">".($system_user->username." [".$system_user->name."]")."</option>";
				}
				?>
				</select>
			</td>
		</tr>
		<tr>
			<td align="right" class="key">
				<label for="tsb_role_id">
					<?php echo JText::_( 'TSB ROLE' ); ?>:
				</label>
			</td>
			<td>
			<select class="text_area required" name="tsb_role_id" id="tsb_role_id">
			<?php
			foreach ($this->roles as $role) {
				echo "<option value=\"".$role->id."\" ".($role->id === $this->users->tsb_role_id ? " selected " : "") . ">".$role->name."</option>";
			}
			?>
			</select>
			</td>
		</tr>
	</table>
	</fieldset>
</div>
<script language="JavaScript" type="text/javascript">
$('tsb_role_id').
</script>

<div class="clr"></div>
<input type="hidden" name="option" value="com_ju_tsb" />
<input type="hidden" name="task" value="" />
<input type="hidden" name="controller" value="users" />
</form>
